#pragma once

#include "materialeffect.h"
#include <osg\Vec4>
#include <osgSim\Impostor>
#include <osg/NodeCallback>

namespace VrDataCore
{
	class AlphaEffectUpdateCallback;

	class VRDATACORE_EXPORT AlphaEffect:public MaterialEffect
	{
	public:
		AlphaEffect();
	protected:
		~AlphaEffect();
	public:
		virtual void buildPropertyMap();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
		void setOpenAlpha(QString open);
		QString getOpenAlpha();
		void install();
		void uninstall();
	private:
		QString											_isOpen;
		bool											_haveVisitor;
		osg::ref_ptr<osgSim::Impostor>					_impostor;
		osg::ref_ptr<AlphaEffectUpdateCallback>			_alphaEffectUpdateCallback;
	};

	class AlphaEffectUpdateCallback : public osg::NodeCallback
	{
	public:
		AlphaEffectUpdateCallback(AlphaEffect* ba)
		{
			_alphaEffect = ba ;
		}
		~AlphaEffectUpdateCallback(){} ;
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
		{
			if( !_alphaEffect )
				return ;
			_alphaEffect->install() ;
		}
	protected:
		AlphaEffect*						_alphaEffect;
	};
}